/**
* @version v 1.3.1 2012/03/18
* @package Nerv Widgets, nw.js
* @subpackage Nerv Form, form.js
* @author Manuele Castellan <manuele.castellan@gmail.com>
*
* @copyright    Copyright (C) Copyright (c) 2009 Manuele Castellan. All rights reserved.
* @license        GNU/GPLv3, see LICENSE
*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/

NW3.form = {};

/** Button */
NW3.form.Button = function(params) {
	if(!params) params = false;
	/* CREO OGGETTO PULSANTE begin */
	var obj = {
		id : null,
		text	: '',							// nome bottone
		value	: '',							// value bottone
		image   : null,							// icon
		title	: '',							// titolo bottone
		width : null,							// larghezza
		arrow : null,							// immagine freccia per popupmenu
		object : null,							// elemento button
		enabled : true,							// enabled? (true/false)
		active : false,							// pressed? (false/true)
		status : false,							// setta stato pulsante
		onclick : false,						// user onclick
		onmouseover : false,					// user onmouseover
		onmouseout : false,						// user onmouseout
		onmousedown : false,					// user onmousedown
		onmouseup : false,						// user onmouseup
		classprefix : 'NWFormButton',			// prefisso classe
		classadded : '',						// classi aggiuntive
		popup : null,							// array bottoni usati per creare popup
		
		buttonBoxClass : null,		// class object
		buttonCloseClass : null,	// class object
		
		replace	: null
	};
	/* CREO OGGETTO PULSANTE end */
	
	
	/* CREO PULSANTE begin */
	// bottone -- NWToolbarCreatorButton
	obj.object = document.createElement("a");
	
	// creo text
	var buttonBox_text = document.createElement("span");
	obj.object.appendChild(buttonBox_text);
	
	// setta classi default
	obj.setDefaultClasses = function(){
		NW3.rendering.addClass(obj.object, obj.classprefix);
		NW3.rendering.addClass(obj.object, obj.classadded);
	};
	
	// rimuove tutte le classi
	obj.removeClasses = function(){
		//NW3.rendering.removeClass(obj.object, obj.classprefix);
		//NW3.rendering.removeClass(obj.object, obj.classadded);
		
		NW3.rendering.removeClass(obj.object, obj.classprefix + "Down");
		
		NW3.rendering.removeClass(obj.object, obj.classprefix + "Pressed");
		
		NW3.rendering.removeClass(obj.object, obj.classprefix + "PressedOver");
		
		NW3.rendering.removeClass(obj.object, obj.classprefix + "PressedDown");
		
		NW3.rendering.removeClass(obj.object, obj.classprefix + "Over");
		
		NW3.rendering.removeClass(obj.object, obj.classprefix + "Disabled");
	};
	
	// metodo che attiva gli eventi
	obj.setEvents = function(){
		// setto onClick
		obj.funcClick = function(ev){
			// eseguo funzione utente
			if(obj.onclick) obj.onclick(obj.id, obj);
		};
		
		NW3.event.addEvent(obj.object, "click", obj.funcClick);
		
		obj.setOnMouseOver = function(){
			obj.removeClasses();
			
			if(obj.active){
				NW3.rendering.addClass(obj.object, obj.classprefix + "PressedOver");
			}
			else{
				NW3.rendering.addClass(obj.object, obj.classprefix + "Over");
			}
			
			// eseguo funzione utente
			if(obj.onmouseover) obj.onmouseover(obj.id, obj);
		};
		
		// setto mouseover
		obj.funcMouseover = function(ev){
			obj.setOnMouseOver();
		};
		
		NW3.event.addEvent(obj.object, "mouseover", obj.funcMouseover);
		
		obj.setOnMouseOut = function(){
			obj.removeClasses();
			
			if(obj.active){
				NW3.rendering.addClass(obj.object, obj.classprefix + "Pressed");
				//NW3.rendering.addClass(buttonBox_close, obj.classprefix + "ClosePressed");
			}
			else{
				//NW3.rendering.addClass(obj.object, obj.classprefix + "");
				//NW3.rendering.addClass(buttonBox_close, obj.classprefix + "Close");
			}
			
			// eseguo funzione utente
			if(obj.onmouseout) obj.onmouseout(obj.id, obj);
		};
		
		// setto mouseout
		obj.funcMouseout = function(ev){
			obj.setOnMouseOut();
		};
		
		NW3.event.addEvent(obj.object, "mouseout", obj.funcMouseout);
		
		obj.setOnMouseDown = function(){
			obj.removeClasses();
			
			if(obj.active){
				NW3.rendering.addClass(obj.object, obj.classprefix + "PressedDown");
				//NW3.rendering.addClass(buttonBox_close, obj.classprefix + "ClosePressedDown");
			}
			else{
				NW3.rendering.addClass(obj.object, obj.classprefix + "Down");
				//NW3.rendering.addClass(buttonBox_close, obj.classprefix + "CloseDown");
			}
		};
		
		// setto mousedown
		obj.funcMousedown = function(ev){
			NW3.event.stopEvent(obj.object, NW3.client.isIE() ? window.event : ev);
			//NW3.event.stopEvent(buttonBox_close, NW3.client.isIE() ? window.event : ev);
			
			obj.setOnMouseDown();
			
			// eseguo funzione utente
			if(obj.onmousedown) obj.onmousedown(obj.id, obj, ev);
		};
		
		NW3.event.addEvent(obj.object, "mousedown", obj.funcMousedown);
		
		obj.setOnMouseUp = function(){
			obj.removeClasses();
			
			if(obj.active){
				NW3.rendering.addClass(obj.object, obj.classprefix + "PressedOver");
				//NW3.rendering.addClass(buttonBox_close, obj.classprefix + "ClosePressedOver");
			}
			else{
				NW3.rendering.addClass(obj.object, obj.classprefix + "Over");
				//NW3.rendering.addClass(buttonBox_close, obj.classprefix + "CloseOver");
			}
		};
		
		// setto mouseup
		obj.funcMouseup = function(ev){
			NW3.event.stopEvent(obj.object, NW3.client.isIE() ? window.event : ev);
			//NW3.event.stopEvent(buttonBox_close, NW3.client.isIE() ? window.event : ev);
			
			obj.setOnMouseUp();
			
			// eseguo funzione utente
			if(obj.onmouseup) obj.onmouseup(obj.id, obj, ev);
		};
		
		NW3.event.addEvent(obj.object, "mouseup", obj.funcMouseup);
	};
	
	obj.removeEvents = function(){
		if(obj.funcClick) NW3.event.removeEvent(obj.object, "click", obj.funcClick);
		if(obj.funcMouseover) NW3.event.removeEvent(obj.object, "mouseover", obj.funcMouseover);
		if(obj.funcMouseout) NW3.event.removeEvent(obj.object, "mouseout", obj.funcMouseout);
		if(obj.funcMouseup) NW3.event.removeEvent(obj.object, "mouseup", obj.funcMouseup);
		if(obj.funcMousedown) NW3.event.removeEvent(obj.object, "mousedown", obj.funcMousedown);
	};
	/* SETTO EVENTI PULSANTE end */
	
	
	/* METODI */
	// recupera stato bottone
	obj.getStatus = function(){
		return obj.status;
	};
	
	// funzione che cambia lo stato del bottone
	obj.setStatus = function(op){
		obj.removeClasses();
		
		switch(op){
			case "enabled":
				if(!obj.enabled) obj.setEvents();
				obj.enabled = true;
				
				obj.active = false;
				
				obj.status = op;
				break;
			case "disabled":
				NW3.rendering.addClass(obj.object, obj.classprefix + "Disabled");
				
				obj.enabled = false;

				obj.removeEvents();
				
				obj.status = op;
				break;
			case "pressed":
				NW3.rendering.addClass(obj.object, obj.classprefix + "Pressed");
				
				obj.active = true;
				
				obj.status = op;
				break;
		}
	};
	
	// aggiungi bottone popup
	obj.addPopupButton = function(val){
		if( (val != '') && (val != 'undefined') && (val != null) ){
			obj.popup = val;
		}
	};
	
	// setta classe per pulsante
	obj.setClass = function(val){
		if( (val != '') && (val != 'undefined') && (val != null) ){
			obj.classprefix = val;
		}
	};
	
	// aggiunge classe al pulsante
	obj.addClass = function(val){
		if( (val != '') && (val != 'undefined') && (val != null) ){
			obj.classadded = val;
		}
	};
	
	// setto freccia del pulsante per popup
	obj.setArrow = function(val){
		if(val){
			obj.arrow = val;
		}
		else obj.arrow = false;
	};
	
	// setta id del bottone
	obj.setId = function(val){
		obj.id = val;
	};
	
	// setta il titolo
	obj.setTitle = function(val){
		if(val != ''){
			obj.title = val;
			buttonBox_text.title = val;
		}
	};
	
	// recupera il titolo
	obj.getTitle = function(){
		return obj.title;
	};
	
	// recupera il testo
	obj.getText = function(){
		return obj.text;
	};
	
	// setta il testo
	obj.setText = function(val){
		if(val != ''){
			obj.text = val;
			buttonBox_text.innerHTML = obj.text;
		}
	};
	
	// recupera il value
	obj.getValue = function(){
		return obj.value;
	};
	
	// setta il value
	obj.setValue = function(val){
		if(val != ''){
			obj.value = val;
		}
	};
	
	// setta immagine
	obj.setImage = function(val){
		if(val != ''){
			// image
			obj.image = val;
			
			buttonBox_text.style.backgroundImage = "url('"+obj.image+"')";
			
			NW3.rendering.addClass(buttonBox_text, obj.classprefix + "Img");
		}
	};
	
	// setta width
	obj.setWidth = function(val){
		if(val){
			if(NW3.client.isIE()) val = parseInt(val) + 12;
			obj.width = val;
		}
		obj.object.style.width = obj.width;
	};
	
	// setta onclick
	obj.onClick = function(val){
		if(val != ''){
			obj.onclick = val;
		}
	};
	
	// setta onmouseover
	obj.onMouseOver = function(val){
		if(val != ''){
			obj.onmouseover = val;
		}
	};
	
	// setta onmouseout
	obj.onMouseOut = function(val){
		if(val != ''){
			obj.onmouseout = val;
		}
	};
	
	// setta onmousedown
	obj.onMouseDown = function(val){
		if(val != ''){
			obj.onmousedown = val;
		}
	};
	
	// setta onmouseup
	obj.onMouseUp = function(val){
		if(val != ''){
			obj.onmouseup = val;
		}
	};
	
	// key shortcut
	obj.setKeyShortcut = function(val, func){
		if(val != ''){
			obj.keyshortcut = val;
			obj.keyshortcutfunc = func;
		}
	};
	
	// restituisce l'oggetto
	obj.output = function(){
		obj.setDefaultClasses();
		
		if(obj.enabled) obj.setEvents();
		
		// setto classi
		if(obj.enabled){
			if(!obj.active){
				obj.setStatus('enabled');
			}
			else{
				obj.setStatus('pressed');
			}
		}
		
		if(obj.popup) obj.setArrow(true);
		
		//SHORTCUT
		if(obj.keyshortcut){
			// cerco lettera nel testo
			text = '';
			t_found = 0;
			for(c=0; obj.text.length>=c; c++){
				if(obj.text[c]){
					if(t_found == 0){
						if(obj.text[c].toLowerCase() == obj.keyshortcut.toLowerCase()){
							text += '<u>' + obj.text[c] + '</u>';
							t_found++;
						}
						else text += obj.text[c];
					}
					else text += obj.text[c];
				}
			}
			if(text != "") obj.setText(text);
			
			// setto eventi onkey per shortcut
			obj.setOnKeyUp = function(){
				obj.removeClasses();
				
				if(obj.active){
					NW3.rendering.addClass(obj.object, obj.classprefix + "Pressed");
				}
				else{
					NW3.rendering.addClass(obj.object, obj.classprefix);
				}
			};
			
			obj.funcKeyShortcutOnKeyUp = function(e){
				if(obj.keyshortcut){
					key = NW3.client.getCharCode(e);
					if(key){
						if(key.toLowerCase() == obj.keyshortcut.toLowerCase()){
							obj.setOnKeyUp();
							
							obj.keyshortcutfunc();
						}
					}
				}
			};
			NW3.event.addEvent(document, "keyup", obj.funcKeyShortcutOnKeyUp);
			
			
			
			obj.setOnKeyDown = function(){
				obj.removeClasses();
				
				if(obj.active){
					NW3.rendering.addClass(obj.object, obj.classprefix + "PressedDown");
				}
				else{
					NW3.rendering.addClass(obj.object, obj.classprefix + "Down");
				}
			};
			
			// setto keydown
			obj.funcKeydown = function(e){
				if(obj.keyshortcut){
					key = NW3.client.getCharCode(e);
					if(key){
						if(key.toLowerCase() == obj.keyshortcut.toLowerCase()){
							NW3.event.stopEvent(obj.object, NW3.client.isIE() ? window.event : e);
							NW3.event.stopEvent(obj.object, NW3.client.isIE() ? window.event : e);
							
							obj.setOnKeyDown();
							
							// eseguo funzione utente
							if(obj.onkeydown) obj.onkeydown(obj.id, obj, ev);
						}
					}
				}
			};
			NW3.event.addEvent(document, "keydown", obj.funcKeydown);
		}
		
		
		// arrow bottom
		if(obj.arrow){
			buttonBox_img_arrow_bottom.className = obj.classprefix + 'Arrow';
			buttonBox_close.appendChild(buttonBox_img_arrow_bottom);
		}
		
		// crea menu popup
		if(obj.popup){
			// visualizzo il popup al click del bottone
			obj.onMouseOver(function(){
				// attivo freccia
				obj.setArrow(true);
				//if(obj.text == 'Apri') alert(obj.object.parentNode.offsetWidth);
				//buttonBox.style.width = obj.object.parentNode.offsetWidth;
				// setto position top e left per popup
				obj.popup.setTop(obj.object.offsetTop);
				obj.popup.setLeft(obj.object.parentNode.offsetWidth - 6);
				obj.popup.show();
			});
			
			obj.onMouseOut(function(){
				// attivo freccia
				//obj.setArrow(true);
				//if(obj.text == 'Apri') alert(obj.object.parentNode.offsetWidth);
				//buttonBox.style.width = obj.object.parentNode.offsetWidth;
				// setto position top e left per popup
				//obj.popup.setTop(obj.object.offsetTop);
				//obj.popup.setLeft(obj.object.parentNode.offsetWidth - 4);
				obj.popup.hide();
			});
			
			// aggiungo al conteiner
			obj.object.appendChild(obj.popup.output());
		}
		
		return obj.object;
	};
	
	obj.print = function(){
		NW3.core.object.print(obj.output());
	};
	
	obj.replace = function(targetElement){
		NW3.core.object.replace(targetElement, obj.output());
	};
	
	obj.insertAfter = function(targetElement){
		NW3.core.object.insertAfter(obj.output(), targetElement);
	};
	
	obj.insertBefore = function(targetElement){
		NW3.core.object.insertBefore(obj.output(), targetElement);
	};
	
	obj.appendChild = function(targetElement){
		NW3.core.object.appendChild(obj.output(), targetElement);
	};
	
	// set params
	if(params){
		if(params.id)
			obj.setId(params.id);
		if(params.text)
			obj.setText(params.text);
		if(params.value)
			obj.setValue(params.value);
		if(params.width)
			obj.setWidth(params.width);
		if(params.image)
			obj.setImage(params.image);
		if(params.status)
			obj.setStatus(params.status);
		if(params.keyshortcut)
			obj.setKeyShortcut(params.keyshortcut.key, params.keyshortcut.action);
		obj.onClick(params.onclick);
		obj.onMouseOver(params.onmouseover);
		obj.onMouseOut(params.onmouseout);
		obj.onMouseDown(params.onmousedown);
		obj.onMouseUp(params.onmouseup);
		
		if(params.replace && typeof params.replace != 'function'){
			targetObj = NW3.getElement(params.replace);
			
			switch(targetObj.nodeName){
				case 'A':
					obj.setText(targetObj.innerHTML);
					if(!params.onclick && !params.onmouseover && !params.onmouseout && !params.onmousedown && !params.onmouseup){
						obj.href = targetObj.getAttribute("href");
						obj.onMouseUp(function(){
							document.location.href = obj.href;
						});
					}
					break;
				case 'INPUT':
					obj.setText(targetObj.getAttribute("value"));
					break;
			}
			obj.replace( targetObj );
		}
	}
	
	return obj;
};


NW3.form.Text  = function(params){
	this.oInput = document.createElement('input');
	this.oInput.type = (params.inputType)?params.inputType:'text';
	
	// creo oggetto
	var obj = {
		name : ((!NW3.core.array.isArray(params)) ? params : ''),	// field name
		value : null,						// valore input
		id: null,							// id input
		title : '',						// input title
		disabled : null,					// input disable
		//uneditable	:	null,				// input uneditable
		width : null,						// input width
		object : this.oInput,			// contenitore
		box : this.oBox,					// box
		close : this.oClose,				// close
		labeltext : null,					// testo etichetta
		labelposition : 'left',				// posizione label
		olabel : this.oLabel,				// oggetto etichetta
		classprefix : 'NWFormText',		// prefisso classe
		
		onmousedown : null,
		
		onkeyup : false,
		onkeydown : false,
		onblur : false,
		
		ajaxUrl : null
	};
	
	obj.replace = function(targetElement){
		NW3.core.object.replace(targetElement, obj.output());
	};
	
	// add contents from url with Ajax
	obj.loadAjaxUrl = function(ajaxUrl){
		if(ajaxUrl) obj.ajaxUrl = ajaxUrl;
		
		if(obj.ajaxUrl){
			NW3.ajax.Request(obj.ajaxUrl, {
				method : 'GET',
				onComplete : function(response){
					obj.oContents.innerHTML = response.responseText;
				}
			});
		}
	};
	
	// prefisso classe disabled
	obj.classprefix_disabled = obj.classprefix + 'Disabled';
	
	// setta id campo
	obj.setId = function(val){
		if(val){
			obj.id = val;
			obj.object.id = val;
		}
	};
	
	// recupera id campo
	obj.getId = function(){
		return obj.object.id;
	};
	
	// setta name campo
	obj.setName = function(val){
		if(val){
			obj.name = val;
			obj.object.name = val;
		}
	};
	
	// recupera name campo
	obj.getName = function(){
		return obj.object.name;
	};
	
	// setta onmouseup
	obj.onMouseUp = function(val){
		if(val){
			obj.onmouseup = val;
		}
	};
	
	// setta onmousedown
	obj.onMouseDown = function(val){
		if(val){
			obj.onmousedown = val;
		}
	};
	
	// aggiungo evento onkeyup
	obj.onKeyUp = function(val){
		if(val != ''){
			obj.onkeyup = val;
		}
	};
	
	// aggiungo evento onblur
	obj.onBlur = function(val){
		if(val){
			obj.onblur = val;
		}
	};
	
	// aggiungo evento onkeydown
	obj.onKeyDown = function(val){
		if(val != ''){
			obj.onkeydown = val;
		}
	};
	
	// setta classe
	obj.setClass = function(val){
		if(val){
			obj.classprefix = val;
		}
		// prefisso classe disabled
		obj.classprefix_disabled = obj.classprefix + 'Disabled';
	};
	
	// classi
	obj.setObjClass = function(){
		NW3.rendering.addClass(obj.object, obj.classprefix);
	};
	
	obj.removeObjClass = function(classname){
		NW3.rendering.removeClass(obj.object, classname);
	};
	
	// recupera valore
	obj.getValue = function(){
		return obj.object.value;
	};
	
	// setto valore
	obj.setValue = function(val){
		obj.value = val;
		obj.object.value = val;
	};
	
	// setto width
	obj.setWidth = function(val){
		if(val){
			obj.width = val;
			val = parseInt(val) + 3;
			obj.object.style.width = val.toString() + 'px';
		}
	};
	
	// recupero width
	obj.getWidth = function(){
		return obj.width;
	};
	
	// setto title
	obj.setTitle = function(val){
		if(val){
			obj.title = val;
			obj.object.title = val;
		}
	};
	
	// recupera stato
	obj.getStatus = function(){
		return obj.object.disabled;
	};
	
	// setta lo stato
	obj.setStatus = function(op){
		switch(op){
			case "enabled":
				obj.object.disabled = false;
				obj.object.setAttribute('readOnly', false);
				
				NW3.rendering.removeClass(obj.object, obj.classprefix_disabled);
				
				obj.setEvents();
				//obj.status = op;
				
				break;
			case "disabled":
				obj.object.disabled = true;
				
				NW3.rendering.addClass(obj.object, obj.classprefix_disabled);
				
				obj.removeEvents();
				//obj.status = op;
				
				break;
			case "readonly":
				obj.object.setAttribute('readOnly', true);
				obj.object.disabled = false;
				
				obj.removeEvents();
				//obj.status = op;
				
				break;
		}
	};
	
	obj.setEvents = function(){
		obj.funcKeyup = function(func){
			if(obj.onkeyup) obj.onkeyup(obj);
		};
		NW3.event.addEvent(obj.object, "keyup", obj.funcKeyup);
		
		obj.funcBlur = function(func){
			if(obj.onblur) obj.onblur(obj);
		};
		NW3.event.addEvent(obj.object, "blur", obj.funcBlur);
		
		obj.funcKeydown = function(ev){
			if(obj.onkeydown) obj.object.onkeydown = obj.onkeydown;
		};
		NW3.event.addEvent(obj.object, "keydown", obj.funcKeydown);
		
		obj.funcMouseup = function(ev){
			if(obj.onmouseup) obj.onmouseup();
		};
		NW3.event.addEvent(obj.object, "mouseup", obj.funcMouseup);
		
		obj.funcMousedown = function(ev){
			if(obj.onmousedown) obj.onmousedown();
		};
		NW3.event.addEvent(obj.object, "mousedown", obj.funcMousedown);
	};
	
	obj.removeEvents = function(){
		if(obj.funcKeyup) NW3.event.removeEvent(obj.object, "keyup", obj.funcKeyup);
		if(obj.funcBlur) NW3.event.removeEvent(obj.object, "blur", obj.funcBlur);
		if(obj.funcKeydown) NW3.event.removeEvent(obj.object, "keydown", obj.funcKeydown);
		if(obj.funcMouseup) NW3.event.removeEvent(obj.object, "mouseup", obj.funcMouseup);
		if(obj.funcMousedown) NW3.event.removeEvent(obj.object, "mousedown", obj.funcMousedown);
	};
	
	
	obj.output = function(){
		obj.object.name = obj.name;
		
		obj.setClass();
		obj.setObjClass();
		
		if(obj.getStatus() == 'disabled') obj.removeEvents();
		else obj.setEvents();
		
		return obj.object;
	};
	
	obj.print = function(){
		NW3.core.object.print(obj.output());
	};
	
	obj.replace = function(targetElement){
		NW3.core.object.replace(targetElement, obj.output());
	};
	
	obj.insertAfter = function(targetElement){
		NW3.core.object.insertAfter(obj.output(), targetElement);
	};
	
	obj.insertBefore = function(targetElement){
		NW3.core.object.insertBefore(obj.output(), targetElement);
	};
	
	obj.appendChild = function(targetElement){
		NW3.core.object.appendChild(obj.output(), targetElement);
	};
	
	// set params
	if(NW3.core.object.isObject(params)){
		if(params.id) obj.setId(params.id);
		obj.setName(params.name);
		if(params.value) obj.setValue(params.value);
		obj.setWidth(params.width);
		obj.setStatus(params.status);
		obj.onMouseDown(params.onmousedown);
		obj.onKeyUp(params.onkeyup);
		obj.onKeyDown(params.onkeydown);
		obj.onBlur(params.onblur);
		
		if(params.replace){
			targetObj = NW3.getElement(params.replace);
			
			switch(targetObj.nodeName){
				case 'INPUT':
					obj.setValue(targetObj.getAttribute("value"));
					obj.setName(targetObj.getAttribute("name"));
					break;
			}
			obj.replace( targetObj );
		}
		
		if(params.ajaxUrl) obj.loadAjaxUrl(params.ajaxUrl);
	}
	
	return obj;
};


NW3.form.Textarea  = function(params){
	this.oTextarea = document.createElement('textarea');
	
	// creo oggetto
	var obj = {
		name : ((!NW3.core.array.isArray(params)) ? params : ''),						// field name
		value : null,						// valore input
		title : null,						// input title
		disabled : null,					// input disable
		width : null,						// input width
		height : null,						// input height
		object : this.oTextarea,			// contenitore
		classprefix : 'NWFormTextarea',		// prefisso classe
		
		onkeyup : false,
		
		ajaxUrl : null,
		
		replace : null
	};
	
	// add contents from url with Ajax
	obj.loadAjaxUrl = function(ajaxUrl){
		if(ajaxUrl) obj.ajaxUrl = ajaxUrl;
		
		if(obj.ajaxUrl){
			NW3.ajax.Request(obj.ajaxUrl, {
				method : 'GET',
				onComplete : function(response){
					obj.oContents.innerHTML = response.responseText;
				}
			});
		}
	};
	
	// classi
	obj.setObjClass = function(){
		NW3.rendering.addClass(obj.object, obj.classprefix);
	};
	
	// recupera valore
	obj.getValue = function(){
		return obj.object.value;
	};
	
	// setto valore
	obj.setValue = function(val){
		if(val){
			obj.value = val;
			obj.object.value = val;
		}
	};
	
	// recupera id
	obj.getId = function(){
		return obj.object.id;
	};
	
	// setto id
	obj.setId = function(val){
		if(val){
			obj.id = val;
			obj.object.id = val;
		}
	};
	
	// recupera name
	obj.getName = function(){
		return obj.object.value;
	};
	
	// setto name
	obj.setName = function(val){
		if(val){
			obj.name = val;
			obj.object.name = val;
		}
	};
	
	// setto width
	obj.setWidth = function(val){
		if(val){
			obj.width = val;
			if(NW3.core.string.isInt(val)){
				obj.object.style.width = parseInt(val) + 'px';
			}
			else if (val.indexOf("%")){
				val = parseInt( val.substr(0, val.length-1) );
				val = val - 2;
				obj.object.style.width = val + "%";
			}
		}
	};
	
	// setto height
	obj.setHeight = function(val){
		if(val){
			obj.height = val;
			obj.object.style.height = parseInt(val) + 'px';
		}
	};
	
	// setto title
	obj.setTitle = function(val){
		if(val){
			obj.title = val;
			obj.object.title = val;
		}
	};
	
	// recupera stato
	obj.getStatus = function(){
		return obj.status;
	};
	
	// setta lo stato
	obj.setStatus = function(op){
		switch(op){
			case "enabled":
				obj.object.disabled = false;
				obj.object.setAttribute('readOnly', false);
				obj.status = op;
				
				break;
			case "disabled":
				obj.object.disabled = true;
				obj.status = op;
				
				break;
			case "readonly":
				obj.object.setAttribute('readOnly', true);
				obj.object.disabled = false;
				obj.status = op;
				
				break;
		}
	};
	
	// aggiungo evento onkeyup
	obj.onKeyUp = function(val){
		if(val != ''){
			obj.onkeyup = val;
		}
	};
	
	// setta onmousedown
	obj.onMouseDown = function(val){
		if(val){
			obj.onmousedown = val;
		}
	};
	
	// aggiungo evento onblur
	obj.onBlur = function(val){
		if(val){
			obj.onblur = val;
		}
	};
	
	// aggiungo evento onkeydown
	obj.onKeyDown = function(val){
		if(val != ''){
			obj.onkeydown = val;
		}
	};
	
	//var oTextareaEvents = new NW3.event.Handling(obj.textarea);
	NW3.event.addEvent(obj.object, 'keyup', function(func){
		// eseguo funzione utente
		if(obj.onkeyup) obj.onkeyup(obj);
	});
	NW3.event.addEvent(obj.object, 'blur', function(func){
		// eseguo funzione utente
		if(obj.onblur) obj.onblur(obj);
	});
	
	// aggiungo evento onkeydown
	NW3.event.addEvent(obj.object, "keydown", function(ev){
		if(obj.onkeydown) obj.object.onkeydown = obj.onkeydown;
	});
	
	// setta onmousedown
	NW3.event.addEvent(obj.object, "mousedown", function(ev){
		if(obj.onmousedown) obj.onmousedown();
	});
	
	obj.output = function(){
		obj.object.name = obj.name;
		
		obj.setObjClass();
		
		return obj.object;
	};
	
	obj.print = function(){
		NW3.core.object.print(obj.output());
	};
	
	obj.replace = function(targetElement){
		NW3.core.object.replace(targetElement, obj.output());
	};
	
	obj.insertAfter = function(targetElement){
		NW3.core.object.insertAfter(obj.output(), targetElement);
	};
	
	obj.insertBefore = function(targetElement){
		NW3.core.object.insertBefore(obj.output(), targetElement);
	};
	
	obj.appendChild = function(targetElement){
		NW3.core.object.appendChild(obj.output(), targetElement);
	};
	
	// set params
	if(params){
		if(params.id) obj.setId(params.id);
		obj.setName(params.name);
		obj.setValue(params.value);
		obj.setWidth(params.width);
		obj.setHeight(params.height);
		obj.setStatus(params.status);
		obj.onMouseDown(params.onmousedown);
		obj.onKeyUp(params.onkeyup);
		obj.onKeyDown(params.onkeydown);
		obj.onBlur(params.onblur);
		
		if(params.ajaxUrl) obj.loadAjaxUrl(params.ajaxUrl);
		
		if(params.replace){
			targetObj = NW3.getElement(params.replace);
			
			switch(targetObj.nodeName){
				case 'TEXTAREA':
					obj.setValue(targetObj.innerHTML);
					break;
			}
			obj.replace( targetObj );
		}
	}
	
	return obj;
};

NW3.form.Checkbox = function(params){
	this.oContainer = document.createElement('label');
	
	this.oCheckbox = new NW3.form.Button();
	
	this.oInput = document.createElement('input');
	this.oInput.type = 'hidden';
	
	this.oLabel = document.createElement('span');
	
	// creo oggetto
	var obj = {
		name : ((!NW3.core.object.isObject(params)) ? params : ''), // field name
		id : null,						// id
		value : null,					// field value 
		object : this.oCheckbox,		// oggetto
		input : this.oInput,			// input checkbox
		container : this.oContainer,	// contenitore
		labeltext : null,				// testo etichetta
		olabel : this.oLabel,	// oggetto etichetta
		classprefix : 'NWFormCheckbox',	// prefisso classe
		
		onmouseup : null
	};
	
	// setta valore campo
	obj.setValue = function(val){
		if(val){
			obj.input.setAttribute('value', val);
			obj.value = val;
		}
	};
	
	// recuopera valore campo
	obj.getValue = function(){
		return obj.value;
	};
	
	// setta id campo
	obj.setId = function(val){
		if(val){
			obj.id = val;
			obj.input.id = val;
		}
	};
	
	// recupera id campo
	obj.getId = function(){
		return obj.id;
	};
	
	// setta name
	obj.setName = function(val){
		if(val){
			obj.name = val;
			obj.input.name = val;
		}
	};
	
	// setta tipo input
	obj.setInputType = function(val){
		if(val) obj.inputype = val;
	};
	
	// setta label
	obj.setLabel = function(val, position){
		if(val) obj.labeltext = val;
	};
	
	// setta se premuto
	obj.setPressed = function(status){
		switch(status){
			case false:
				obj.setStatus('enabled');
				obj.input.disabled = 'disabled';
				break;
			case true:
				obj.setStatus('pressed');
				obj.input.disabled = '';
				break;
		}
	};
	
	// recupera stato checkbox
	obj.getStatus = function(){
		return obj.object.getStatus();
	};
	
	// setta stato checkbox
	obj.setStatus = function(op){
		obj.object.setClass(obj.classprefix + 'Field');
		
		switch(op){
			case 'disabled':
				NW3.rendering.addClass(obj.olabel, obj.classprefix + 'LabelDisabled');
				break;
			default:
				NW3.rendering.removeClass(obj.olabel, obj.classprefix + 'LabelDisabled');
				break;
		}
		
		return obj.object.setStatus(op);
	};
	
	obj.setOnMouseUp = function(val){
		if(val != '') obj.onmouseup = val;
	};
	
	obj.onMouseUpEvent = function(ev){
		if(obj.onmouseup) obj.onmouseup(obj);
		
		var status = obj.getStatus();
		if(status != 'disabled'){
			switch(status){
				case 'pressed':
					obj.setPressed(false);
					break;
				default:
					obj.setPressed(true);
					break;
			}
		}
	};
	
	// setta classi
	obj.setObjClass = function(){
		NW3.rendering.addClass(obj.container,obj.classprefix);

		obj.object.setClass(obj.classprefix + 'Field');

		NW3.rendering.addClass(obj.olabel, obj.classprefix + 'Label');
	};
	
	obj.output = function(){
		obj.object.onMouseUp(obj.onMouseUpEvent);
		NW3.event.addEvent(obj.olabel, "mouseup", obj.onMouseUpEvent);
		
		obj.setObjClass();
		
		obj.olabel.innerHTML = '';
		if(obj.labeltext) obj.olabel.innerHTML = obj.labeltext;
		
		obj.container.appendChild(obj.object.output());
		obj.container.appendChild(obj.input);
		obj.container.appendChild(obj.olabel);
		
		obj.setName(obj.name);
		
		obj.setPressed(obj.getStatus());
		
		return obj.container;
	};
	
	obj.print = function(){
		NW3.core.object.print(obj.output());
	};
	
	obj.replace = function(targetElement){
		NW3.core.object.replace(targetElement, obj.output());
	};
	
	obj.insertAfter = function(targetElement){
		NW3.core.object.insertAfter(obj.output(), targetElement);
	};
	
	obj.insertBefore = function(targetElement){
		NW3.core.object.insertBefore(obj.output(), targetElement);
	};
	
	obj.appendChild = function(targetElement){
		NW3.core.object.appendChild(obj.output(), targetElement);
	};
	
	// set params
	if(params){
		if(params.id) obj.setId(params.id);
		obj.setName(params.name);
		obj.setValue(params.value);
		if(params.label) obj.setLabel(params.label.text, params.label.align);
		obj.setStatus(params.status);
		obj.setPressed(params.pressed);
	}
	
	return obj;
};


NW3.form.Radio = function(name){
	var oRadio = NW3.form.Checkbox(name);
	
	NW3.core.object.extend(oRadio, {
		onMouseUpEvent : function(){
			if(oRadio.onmouseup) oRadio.onmouseup(oRadio);
			
			var status = oRadio.object.getStatus();
			if(status != 'disabled'){
				if(!oRadio.object.getStatus()){
					switch(oRadio.object.getStatus()){
						case false:
							oRadio.setPressed(true);
							break;
						case true:
							oRadio.setPressed(false);
							break;
					}
				}
			}
		}
	});
	
	return oRadio;
};



NW3.form.checkboxlist = {
	CheckboxList : function(params){
		params = (NW3.core.object.isObject(params)) ? params : null;
		
		var oUl = document.createElement('ul');
		
		// creo oggetto lista
		var obj = {
			object : oUl,					// oggetto
			list : null,					// array Radios
			status : 'enabled',
			classprefix : 'NWFormCheckbox',	// prefisso classe
			
			limit : null,
			checkedfields : null // count for checked fields
		};
		
		// creo array bottoni
		obj.list = new Array();
		
		// aggiorna stato
		/*obj.update = function(id){
			for(i=0; i<obj.list.length; i++){
				if(obj.list[i].getId() == id){
					obj.list[i].setStatus('pressed');
				}
				else{
					obj.list[i].setStatus('enabled');
				}
			}
		}*/
		
		// setta attivo di default
		obj.setPressed = function(arr_id){
			for(i=0; i<obj.list.length; i++){
				if( (NW3.core.array.isArray(arr_id)) && (NW3.core.array.inArray(obj.list[i].getId()+1, arr_id)) || (obj.list[i].getId()+1 == arr_id) ){
					obj.list[i].setPressed(true);
				}
				else{
					obj.list[i].setPressed(false);
				}
			}
		};
		
		// set limit checkbox checkable
		obj.setLimit = function(numLimit){
			if(NW3.core.string.isInt(numLimit)){
				obj.limit = numLimit;
			}
		};
		// check limit
		obj.checkLimit = function(){
			if(obj.limit > 0){
				if(obj.limit <= obj.checkedfields){
					return false;
				}
				else{
					return true;
				}
			}
			
			return true;
		};
		
		// set checked fields
		obj.setCheckedField = function(op){
			switch(op){	
				case '+':
					obj.checkedfields = obj.checkedfields+1;
					break;
				case '-':
					obj.checkedfields = obj.checkedfields-1;
					break;
			}
		};
		
		// recupera stato checkbox
		obj.getStatus = function(){
			return obj.status;
		};
		
		// setta stato checkbox
		obj.setStatus = function(op){
			for(i=0; i<obj.list.length; i++){
				obj.list[i].setStatus(op);
			}
			
			if(NW3.core.array.isArray(op)){
				for(i=1; i<op.length; i++){
					obj.setCheckedField('+');
				}
			}
			
			obj.status = op;
		};
		
		var bCounter = 0;
		
		// aggiunge checkbox
		obj.addCheckbox = function(oCheckbox){
			var oLi = document.createElement('li');
			
			obj.list.push(oCheckbox);
			
			oCheckbox.setId(bCounter);
			
			// setto classe
			oCheckbox.setClass(obj.classprefix);
			

			NW3.core.object.extend(oCheckbox, {
				onMouseUpEvent : function(){
					var status = oCheckbox.object.getStatus();
					if(status != 'disabled'){	
						if(obj.checkLimit() == false){
							if(oCheckbox.object.getStatus() == 'pressed'){
								obj.setCheckedField('-');
								
								oCheckbox.setPressed(false);
							}
						}
						else {
							if(oCheckbox.object.getStatus() == 'pressed'){
								obj.setCheckedField('-');
								
								oCheckbox.setPressed(false);
							}
							else{
								obj.setCheckedField('+');
								
								oCheckbox.setPressed(true);
							}
						}
					}
				}
			});
			
			oLi.appendChild(oCheckbox.output());
			obj.object.appendChild(oLi);
			
			bCounter++;
		};
		
		obj.newCheckbox = function(par){
			if(par){
				oCheckbox = new NW3.form.checkboxlist.Checkbox(par);
				obj.addCheckbox(oCheckbox);
			}
		};
		
		// stampo tutto
		obj.output = function(){
			obj.object.className = obj.classprefix + 'List';
			
			obj.setPressed(obj.getStatus());
			obj.setStatus(obj.getStatus());
			
			return obj.object;
		};
		
		
		obj.print = function(){
			NW3.core.object.print(obj.output());
		};
		
		obj.replace = function(targetElement){
			NW3.core.object.replace(targetElement, obj.output());
		};
		
		obj.insertAfter = function(targetElement){
			NW3.core.object.insertAfter(obj.output(), targetElement);
		};
		
		obj.insertBefore = function(targetElement){
			NW3.core.object.insertBefore(obj.output(), targetElement);
		};
		
		obj.appendChild = function(targetElement){
			NW3.core.object.appendChild(obj.output(), targetElement);
		};
		
		// set params
		if(params){
			if(params.pressed) obj.setStatus(params.pressed);
			if(params.status) obj.setStatus(params.status);
			if(params.limit) obj.setLimit(params.limit);
		}
		
		return obj;
	},
	
	Checkbox : function(params){
		var oCheckbox = new NW3.form.Checkbox(((!NW3.core.array.isArray(params)) ? params : params.name) + '[]');
		
		oCheckbox.setClass = function(classname){
			oCheckbox.classprefix = classname;
		};
		
		/*oCheckbox.setStatus = function(status){
			oCheckbox.object.setStatus(status);
		};*/
		
		oCheckbox.getId = function(){
			return oCheckbox.object.id;
		};
		
		oCheckbox.setId = function(id){
			oCheckbox.object.setId(id);
		};
		
		/*oCheckbox.onMouseUp = function(fn){
			oCheckbox.object.onMouseUp(fn);
		};*/
		
		// set params
		if(params){
			if(params.id) oCheckbox.setId(params.id);
			oCheckbox.setStatus(params.status);
			if(params.label) oCheckbox.setLabel(params.label.text, params.label.align);
		}
		
		return oCheckbox;
	}
};



NW3.form.radiolist = {
	RadioList : function(params){
		var oSpan = document.createElement('span');
		var oUl = document.createElement('ul');
		
		var oInput = document.createElement('input');
		oInput.type = 'hidden';
		
		// creo oggetto lista
		var obj = {
			name : ((!NW3.core.object.isObject(params)) ? params : params.name), 	// name field
			object : oSpan,				// oggetto
			oul : oUl,
			input : oInput,
			value : null,
			list : null,				// array Radios
			li : null,					// array li
			active : null,				// radio attivo default
			pressedindex: null,			// array index pressed radio
			classprefix : 'NWFormRadio',	// prefisso classe
			align : 'vertical'
		};
		obj.params = ((!NW3.core.object.isObject(params)) ? null : params);
		oInput.name = ((!NW3.core.object.isObject(obj.params)) ? obj.params : obj.params.name);
		
		// creo array bottoni
		obj.list = new Array();
		obj.li = new Array();
		
		// aggiorna stato radios
		obj.update = function(id){
			for(i=0; i<obj.list.length; i++){
				if(obj.list[i].getId() == id){
					obj.setValue(obj.list[i].getValue());
					obj.list[i].setPressed(true);
				}
				else{
					obj.list[i].setStatus('enabled');
				}
			}
		};
		
		// setta allineamento
		obj.setAlign = function(align){
			switch(align){
				case 'horizontal':
				case 'vertical':
					obj.align = align;
					break;
			}
		};
		
		// setta valore
		obj.setValue = function(val){
			if(val){
				obj.value = val;
				obj.input.value = val;
			}
		};
		
		obj.setPressedByPosition = function(pos){
			for(i=0; i<obj.list.length; i++){
				ii = i +1;
				if(ii == pos){
					obj.setPressed(obj.list[i].getId());
				}
			}
		};
		
		// setta radio attivo di default
		obj.setPressed = function(id){
			for(i=0; i<obj.list.length; i++){
				if(obj.list[i].getId() == id -1){
					obj.setValue(obj.list[i].getValue());
					obj.list[i].setPressed(true);
				}
				else{
					obj.list[i].setPressed(false);
				}
			}
			
			obj.update(id);
		};
		
		// recupera stato checkbox
		obj.getStatus = function(){
			return obj.status;
		};
		
		// setta stato checkbox
		obj.setStatus = function(op){
			for(i=0; i<obj.list.length; i++){
				obj.list[i].setStatus(op);
			}
			obj.status = op;
		};
		
		var bCounter = 0;
		
		// aggiunge radio
		obj.addRadio = function(oRadio){
			var oLi = document.createElement('li');
			
			obj.list.push(oRadio);
			obj.li.push(oLi);
			
			oRadio.setId(bCounter);
			
			// setto classe
			oRadio.setClass(obj.classprefix);
			
			// setto onMouseUp
			oRadio.setOnMouseUp(function(oob){
				var status = oRadio.object.getStatus();
				if(status != 'disabled'){
					obj.update(oob.getId());
				}
			});
			
			oLi.appendChild(oRadio.output());
			obj.oul.appendChild(oLi);
			
			bCounter++;
		};
		
		obj.newRadio = function(par){
			if(par){
				oRadio = new NW3.form.radiolist.Radio(par);
				obj.addRadio(oRadio);
			}
		};
		
		// stampo tutto
		obj.output = function(){
			obj.object.className = obj.classprefix + 'List';
			
			obj.object.appendChild(oInput);
			obj.object.appendChild(obj.oul);
			
			for(i=0; i<obj.li.length; i++){
				if(obj.align == 'horizontal'){
					if(NW3.client.isIE()) obj.li[i].style.styleFloat = 'left';
					else obj.li[i].style.cssFloat = 'left';
				}
				else{
					obj.li[i].style.clear = 'both';
				}
			}
			
			obj.setPressed(obj.getStatus());
			obj.setStatus(obj.getStatus());
			
			if(obj.params.pressed) obj.setPressedByPosition(obj.params.pressed);
			
			return obj.object;
		};
		
		obj.print = function(){
			NW3.core.object.print(obj.output());
		};
		
		obj.replace = function(targetElement){
			NW3.core.object.replace(targetElement, obj.output());
		};
		
		obj.insertAfter = function(targetElement){
			NW3.core.object.insertAfter(obj.output(), targetElement);
		};
		
		obj.insertBefore = function(targetElement){
			NW3.core.object.insertBefore(obj.output(), targetElement);
		};
		
		obj.appendChild = function(targetElement){
			NW3.core.object.appendChild(obj.output(), targetElement);
		};
		
		// set params
		if(obj.params){
			if(obj.params.status) obj.setStatus(obj.params.status);
			if(obj.params.align) obj.setAlign(obj.params.align);
		}
		
		return obj;
	},
	
	Radio : function(params){
		var oRadio = new NW3.form.Radio();
		
		oRadio.setClass = function(classname){
			oRadio.classprefix = classname;
		};
		
		/*oRadio.setStatus = function(status){
			oRadio.object.setStatus(status);
		};*/
		
		oRadio.onMouseUp = function(f){
			oRadio.object.onMouseUp(f);
		};
		
		oRadio.getId = function(){
			return oRadio.object.id;
		};
		
		oRadio.setId = function(id){
			oRadio.object.setId(id);
		};
		
		// set params
		if(params){
			if(params.id) oRadio.setId(params.id);
			oRadio.setStatus(params.status);
			if(params.label) oRadio.setLabel(params.label.text, params.label.align);
		}
		
		return oRadio;
	}
};


NW3.form.textlist = {
	TextList : function(){
		var oSpan = document.createElement('span');
		var oUl = document.createElement('ul');
		
		/*var oInput = document.createElement('input');
		oInput.type = 'hidden';
		oInput.name = name;*/
		
		// creo oggetto lista
		var obj = {
			name : name, 				// name field
			object : oSpan,				// oggetto
			oul : oUl,
			//input : oInput,
			value : null,
			list : null,				// array Radios
			textlist : null,			// array text
			li : null,					// array li
			active : null,				// radio attivo default
			classprefix : 'tFormRadio',	// prefisso classe
			align : 'vertical',
			idpressed : 0,
			cleandisabled : false
		};
		
		// creo array bottoni
		obj.list = new Array();
		obj.textlist = new Array();
		obj.li = new Array();
		
		// aggiorna stato radios
		obj.update = function(id){
			for(i=0; i<obj.list.length; i++){
				if(obj.list[i].getId() == id){
					obj.setValue(obj.list[i].getValue());
					obj.textlist[i].setEnabled();
				}
				else{
					obj.list[i].setStatus('enabled');
					obj.textlist[i].setDisabled();
					if(obj.cleandisabled) obj.textlist[i].setValue('');
				}
			}
		};
		
		// clean text if disabled
		obj.setCleanDisabled = function(){
			obj.cleandisabled = true;
		};
		
		// setta allineamento
		obj.setAlignHorizontal = function(){
			obj.align = 'horizontal';
		};
		
		// setta valore
		obj.setValue = function(val){
			if(val){
				obj.value = val;
				obj.input.value = val;
			}
		};
		
		// setta radio attivo di default
		obj.setPressed = function(id){
			if(id) obj.idpressed = id;
			
			for(i=0; i<obj.list.length; i++){
				if(obj.list[i].getId() == obj.idpressed){
					obj.setValue(obj.list[i].getValue());
					obj.list[i].setPressed(true);
				}
				else{
					obj.list[i].setPressed(false);
				}
			}
			
			obj.update(obj.idpressed);
		};
		
		
		var bCounter = 0;
		
		// aggiunge testo
		obj.addText = function(oText){
			var oLi = document.createElement('li');
			
			var oRadio = new NW3.form.textlist.Radio();
			if(oText.getLabel() != ""){
				oRadio.setLabel(oText.getLabel());
				oText.setLabel('');
			}
			oRadio.setLabelPositionBegin();
			
			obj.list.push(oRadio);
			obj.li.push(oLi);
			
			oRadio.setId(bCounter);
			
			// setto classe
			oRadio.setClass(obj.classprefix);
			
			// setto OnMouseUp
			oRadio.setOnMouseUp(function(oob){
				obj.update(oob.getId());
			});
			
			oLi.appendChild(oRadio.output());
			
			obj.textlist.push(oText);
			
			oLi.appendChild(oText.output());
			
			obj.oul.appendChild(oLi);
			
			bCounter++;
		};
		
		// stampo tutto
		obj.output = function(){
			obj.object.className = obj.classprefix + 'List';
			
			//obj.object.appendChild(oInput);
			obj.object.appendChild(obj.oul);
			
			for(i=0; i<obj.li.length; i++){
				if(obj.align == 'horizontal'){
					if(NW3.client.isIE()) obj.li[i].style.styleFloat = 'left';
					else obj.li[i].style.cssFloat = 'left';
				}
				else{
					obj.li[i].style.clear = 'both';
				}
			}
			
			obj.setPressed();
			
			return obj.object;
		};
		
		obj.replace = function(targetElement){
			NW3.core.object.replace(targetElement, obj.output());
		};
		
		obj.insertAfter = function(targetElement){
			NW3.core.object.insertAfter(obj.output(), targetElement);
		};
		
		obj.insertBefore = function(targetElement){
			NW3.core.object.insertBefore(obj.output(), targetElement);
		};
		
		obj.appendChild = function(targetElement){
			NW3.core.object.appendChild(obj.output(), targetElement);
		};
		
		obj.print = function(){
			NW3.core.object.print(obj.output());
		};
		
		return obj;
	},
	
	Text : function(name){
		var oText = new NW3.form.Text(name);
		
		/*oText.setClass = function(classname){
			oText.classprefix = classname;
		}
		
		oText.setStatus = function(status){
			oText.object.setStatus(status);
		}
		
		oText.getId = function(){
			return oText.id;
		}
		
		oText.setId = function(id){
			oText.setId(id);
		}*/
		
		return oText;
		
		/*var param = {
			name : name
		}
		
		param.setValue = function(val){
			if(val) param.value = val;
		}
		
		param.setLabel = function(val){
			if(val) param.label = val;
		}
		
		return param;*/
	},
	
	Radio : function(){
		var oRadio = new NW3.form.Radio();
		
		oRadio.setClass = function(classname){
			oRadio.classprefix = classname;
		};
		
		oRadio.setStatus = function(status){
			oRadio.object.setStatus(status);
		};
		
		oRadio.getId = function(){
			return oRadio.object.id;
		};
		
		oRadio.setId = function(id){
			oRadio.object.setId(id);
		};
		
		return oRadio;
	}
};


NW3.form.File = function(params){
	if(!NW3.core.object.isObject(params)){
		params = null;
		name = name;
	}
	else{
		name = params.name;
	}
	
	this.oSearch = new NW3.form.Button();
	this.oSearch.setText(NW3.lang.Browse + '...');
	
	this.oInput = document.createElement('input');
	
	this.oContainer = document.createElement('div');
	this.oSearchContainer = document.createElement('span');
	this.oTextContainer = document.createElement('span');
	
	this.oInputText = new NW3.form.Text(name + 'file');
	
	// creo oggetto
	var obj = {
		name : name,								// field name
		text : this.oInputText,						// field name
		value : null,								// field value 
		object : this.oSearch,						// oggetto
		input : this.oInput,						// input checkbox
		width : '100',								// width
		inputype : 'file',							// tipo di input
		container : this.oContainer,				// contenitore
		searchcontainer : this.oSearchContainer,	// contenitore
		textcontainer : this.oTextContainer,		// contenitore
		classprefix : 'NWFormFile',					// prefisso classe
		classprefixbutton : 'NWFormButton'			// prefisso classe button
	};
	
	
	// setta width
	obj.setWidth = function(val){
		if(val){
			obj.width = parseInt(val);
			//obj.searchcontainer.style.marginLeft = (obj.width + 30) + 'px';
			obj.text.setWidth(obj.width + 20);
			
			obj.input.style.left = (obj.width - 150) + 'px';
		}
	};
	
	// setta classi
	obj.setObjClass = function(){
		//var oContainerClass = new NW3.rendering(obj.container);
		NW3.rendering.addClass(obj.container, obj.classprefix + 'Container');
		
		//var oInputClass = new NW3.rendering(obj.input);
		NW3.rendering.addClass(obj.input, obj.classprefix + 'Field');
		
		obj.searchcontainer.className = obj.classprefix + 'Button';
		obj.textcontainer.className = obj.classprefix + 'Text';
	};
	
	// recupera stato
	obj.getStatus = function(){
		return obj.status;
	};
	
	// setta lo stato
	obj.setStatus = function(op){
		switch(op){
			case "enabled":
				obj.input.disabled = false;
				obj.input.setAttribute('readOnly', false);
				
				obj.text.setStatus('enabled');
				obj.object.setStatus('enabled');
				
				obj.status = op;
				
				break;
			case "disabled":
				obj.input.disabled = true;
				
				obj.text.setStatus('disabled');
				obj.object.setStatus('disabled');
				
				obj.status = op;
				
				break;
		}
	};
	
	//var oFileEvents = new NW3.event.Handling(obj.input);
	NW3.event.addEvent(obj.input, 'mousedown', function(func){
		obj.object.setOnMouseDown();
	});
	NW3.event.addEvent(obj.input, 'mouseup', function(func){
		obj.object.setOnMouseUp();
	});
	NW3.event.addEvent(obj.input, 'mouseover', function(func){
		obj.object.setOnMouseOver();
	});
	NW3.event.addEvent(obj.input, 'mouseout', function(func){
		obj.object.setOnMouseOut();
	});
	
	obj.output = function(){
		obj.setObjClass();
		
		obj.input.name = obj.name;
		obj.input.type = obj.inputype;
		
		// recupero valore campo
		obj.text.setValue(obj.input.value);
		obj.input.onclick = function(){
			setInterval(function(){ obj.text.setValue(obj.input.value); }, 1200);
		};
		
		// blocco tastiera su text
		obj.text.onKeyDown(function(){
			return false;
		});
		
		obj.setWidth(obj.width);
		
		obj.textcontainer.appendChild(obj.text.output());
		obj.container.appendChild(obj.textcontainer);
		
		obj.searchcontainer.appendChild(obj.object.output());
		obj.container.appendChild(obj.input);
		obj.container.appendChild(obj.searchcontainer);
		
		return obj.container;
	};
	
	obj.print = function(){
		NW3.core.object.print(obj.output());
	};
	
	obj.replace = function(targetElement){
		NW3.core.object.replace(targetElement, obj.output());
	};
	
	obj.insertAfter = function(targetElement){
		NW3.core.object.insertAfter(obj.output(), targetElement);
	};
	
	obj.insertBefore = function(targetElement){
		NW3.core.object.insertBefore(obj.output(), targetElement);
	};
	
	obj.appendChild = function(targetElement){
		NW3.core.object.appendChild(obj.output(), targetElement);
	};
	
	// setto params
	if(params){
		obj.setWidth(params.width);
		if(params.status) obj.setStatus(params.status);
	}
	
	return obj;
};


NW3.form.select = {
	Select : function(params){
		params = ((!NW3.core.object.isObject(params)) ? null : params);
		
		this.oTextSelect = document.createElement('span');
		
		this.oList = document.createElement('div');
		
		this.oUl = document.createElement('ul');
		
		name = ((!NW3.core.object.isObject(params)) ? params : params.name);
		
		this.oInputText = new NW3.form.Text(name + 'file');
		this.oButton = new NW3.form.Button();
		
		this.oInputHidden = document.createElement('input');
		this.oInputHidden.type = 'hidden';
		this.oInputHidden.name = name;
		
		// creo oggetto
		var obj = {
			name : name,								// field name
			otext : this.oInputText,					// field name
			value : null,								// field value 
			object : this.oTextSelect,					// oggetto
			hidden : this.oInputHidden,					// hidden value
			obutton : this.oButton,						// button
			olist : this.oList,							// list
			oul : this.oUl,
			width : '100',								// width
			status : 'enabled',
			liststatus	: 'hidden',
			onmouseup	: null,
			//inputype : 'file',						// tipo di input
			//container : this.oContainer,				// contenitore
			//searchcontainer : this.oSearchContainer,	// contenitore
			//textcontainer : this.oTextContainer,		// contenitore
			classprefix : 'NWFormSelect',				// prefisso classe
			classprefixoption	: 'Option',				// prefisso classe option
			classprefixlist		: 'List',
			classprefixbutton	: 'Button'
		};
		
		// creo array bottoni
		obj.list = new Array();
		//obj.textlist = new Array();
		//obj.li = new Array();
		
		var bCounter = 0;
		
		obj.setWidth = function(val){
			if(val) obj.width = val;
			
			obj.otext.setWidth(obj.width);
			obj.olist.style.width = (parseInt(obj.width)+9) + 'px';
			
			for(i=0; i<obj.list.length; i++){
				obj.list[i].setWidth(obj.width);
			}
		};
		
		// aggiunge options
		obj.add = function(oOption){
			var oLi = document.createElement('li');
			
			obj.list.push(oOption);

			oOption.setId(bCounter);
			
			// setto classe
			oOption.setClass(obj.classprefix + obj.classprefixoption);
			
			// setto onMouseUp
			oOption.onMouseUp(function(id){
				val = (oOption.getValue()) ? oOption.getValue() : oOption.getText();
				obj.otext.setValue(oOption.getText());
				obj.hidden.value = val;
				obj.setListStatus('hidden');
				
				if(obj.onmouseup) obj.onmouseup(id, val);
			});
			
			oLi.appendChild(oOption.output());
			obj.oul.appendChild(oLi);
			
			bCounter++;
		};
		
		// add event onchange
		obj.onChange = function(fn){
			obj.onmouseup = fn;
		};
		
		// recupera stato checkbox
		obj.getStatus = function(){
			return obj.status;
		};
		
		// setta stato checkbox
		obj.setStatus = function(op){
			obj.obutton.setClass(obj.classprefix + obj.classprefixbutton);
			
			obj.obutton.setStatus(op);
			obj.otext.setStatus(op);
			
			obj.status = op;
		};
		
		obj.setListStatus = function(action){
			switch(action){
				case 'hidden':
					value = 'none';
					break;
				case 'visible':
					value = 'block';
					break;
			}
			obj.olist.style.display = value;
			
			obj.liststatus = action;
		};
		
		obj.statusToggle = function(){
			if(obj.getListStatus() == 'hidden') obj.setListStatus('visible');
			else obj.setListStatus('hidden');
		};
		
		obj.getListStatus = function(){
			return obj.liststatus;
		};
		
		obj.setSelected = function(id){
			for(i=0; i<obj.list.length; i++){
				ii = i + 1;
				val = (obj.list[i].getValue()) ? obj.list[i].getValue() : obj.list[i].getText();
				if(id == val){
					obj.otext.setValue(obj.list[i].getText());
					obj.hidden.value = val;
				}
			}
		};
		
		obj.newOption = function(pars){
			oOption = new NW3.form.select.Option(pars);
			if(pars.image) oOption.setImage(pars.image);
			obj.add(oOption);
		};
		
		// get serialized options from url with Ajax
		obj.loadAjaxUrl = function(ajaxUrl){
			if(ajaxUrl) obj.ajaxUrl = ajaxUrl;
			
			if(obj.ajaxUrl){
				var options = null;
				
				oAjax = new NW3.ajax.Request(obj.ajaxUrl, {
					method : 'GET',
					onComplete : function(response){
						options = JSON.parse(response.responseText);
						
						for(var i in options){
							obj.newOption(options[i]);
						}
					}
				});
			}
		};
		
		obj.output = function(){
			obj.otext.setValue('');
			obj.hidden.value = '';
			
			obj.olist.style.display = 'none';
			
			if(obj.getStatus() != 'disabled') obj.otext.setStatus('readonly');
			
			/** nascondo se viene cliccata la pagina
			var oWinEvent = new NW3.event.Handling(document);
			oWinEvent.addEvent('click', function(){
				obj.setStatus('hidden');
			});*/
			
			// evento bottone
			obj.obutton.onClick(function(){
				obj.statusToggle();
			});
			
			// evento text
			obj.otext.onMouseUp(function(){
				obj.statusToggle();
			});
			
			obj.obutton.setClass(obj.classprefix + obj.classprefixbutton);
			
			obj.object.appendChild(obj.otext.output());
			obj.object.appendChild(obj.hidden);
			obj.object.appendChild(obj.obutton.output());
			//obj.object.appendChild(document.createElement('br'));
			obj.object.appendChild(obj.olist);
			obj.olist.appendChild(obj.oul);
			
			//var oObjectClass = new NW3.rendering(obj.object);
			NW3.rendering.addClass(obj.object, obj.classprefix);
			
			//var oListClass = new NW3.rendering(obj.olist);
			NW3.rendering.addClass(obj.olist, obj.classprefix + obj.classprefixlist);
			
			if(params.selected) obj.setSelected(params.selected);
			
			obj.setWidth();
			
			return obj.object;
		};
		
		obj.print = function(){
			NW3.core.object.print(obj.output());
		};
		
		obj.replace = function(targetElement){
			NW3.core.object.replace(targetElement, obj.output());
		};
		
		obj.insertAfter = function(targetElement){
			NW3.core.object.insertAfter(obj.output(), targetElement);
		};
		
		obj.insertBefore = function(targetElement){
			NW3.core.object.insertBefore(obj.output(), targetElement);
		};
		
		obj.appendChild = function(targetElement){
			NW3.core.object.appendChild(obj.output(), targetElement);
		};
		
		// setto params
		if(params){
			obj.setWidth(params.width);
			obj.setStatus(params.status);
			if(params.selected) obj.setSelected(params.selected);
		}
		
		return obj;
	},
	
	Option : function(pars){
		var oOption = new NW3.form.Button(pars);
		
		oOption.setClass = function(classname){
			oOption.classprefix = classname;
		};
		
		/*oOption.setStatus = function(status){
			oOption.object.setStatus(status);
		}
		
		oOption.getId = function(){
			return oOption.object.id;
		}
		
		oOption.setId = function(id){
			oOption.object.setId(id);
		}*/
		
		return oOption;
	}
};

NW3.form.dimmer = {
	Dimmer : function(params){
		params = ((!NW3.core.object.isObject(params)) ? null : params);
		
		this.oContainer = document.createElement('span');
		this.oInputText = new NW3.form.Text('hour');
		this.oButtonUp = new NW3.form.dimmer.Button();
		this.oButtonUp.setText('>');
		
		this.oButtonDown = new NW3.form.dimmer.Button();
		this.oButtonDown.setText('<');
		
		name = ((!NW3.core.object.isObject(params)) ? params : params.name);
		
		var obj = {
			name : name,								// field name
			otext : this.oInputText,					// field text
			value : 0,							    	// field value
			valuearray : null,
			valuemin : null,
			valuemax : null,
			object : this.oContainer,					// oggetto
			addbuttons : false,
			obuttonup 	: this.oButtonUp,				// button Up
			obuttondown : this.oButtonDown,				// button Down
			onmouseup : null,
			width : '20',								// width
			status : 'enabled',
			classprefix : 'NWFormDimmer'				// prefisso classe
		};
		
		obj.onMouseUp = function(fn){
			obj.onmouseup = fn;
		};
		
		obj.getValue = function(){
			return obj.value;
		};
		
		obj.setValue = function(val){
			if(val){
				obj.value = val;
				obj.otext.setValue(obj.value);
			}
		};
		
		obj.setRange = function(min, max){
			if(min) obj.valuemin = min;
			if(max) obj.valuemax = max;
		};
		
		obj.setValueArray = function(val, arr){
			if(val) obj.setValue(arr[NW3.core.array.arraySearch(val, arr)]);
			if(NW3.core.array.isArray(arr)){
				obj.valuearray = arr;
				
				obj.setRange('0', arr.length-1);
			}
		};
		
		// recupera stato checkbox
		obj.getStatus = function(){
			return obj.status;
		};
		
		// setta stato checkbox
		obj.setStatus = function(op){
			//obj.obuttonup.setClass(obj.classprefix + 'Up');
			//obj.obuttondown.setClass(obj.classprefix + 'Down');
			
			obj.obuttonup.setStatus(op);
			obj.obuttondown.setStatus(op);
			obj.otext.setStatus(op);
			
			obj.status = op;
		};
		
		obj.setWidth = function(val){
			if(val) obj.width = val;
		};
		
		obj.addButtons = function(up, down){
			if(up && down){
				obj.obuttonup = up;
				obj.obuttondown = down;
				
				obj.addbuttons = true;
			}
		};
		
		obj.output = function(){
			obj.object.className = obj.classprefix;
			obj.obuttonup.addClass(obj.classprefix + 'Up');
			obj.obuttondown.addClass(obj.classprefix + 'Down');
			
			obj.otext.setWidth(obj.width);
			obj.object.appendChild(obj.otext.output());
			
			if(!obj.addbuttons){
				obj.obuttondown.onMouseUp(function(){
					getNumberDown = obj.otext.getValue();
					
					if(obj.valuearray) getNumberDown = new Number(NW3.core.array.arraySearch(getNumberDown, obj.valuearray));
					else getNumberDown = new Number(getNumberDown);
					
					if(obj.valuemax){
						if(obj.valuemin == getNumberDown) textValueDown = getNumberDown;
						else textValueDown = getNumberDown - 1;
					}
					else textValueDown = getNumberDown - 1;
					
					if(obj.valuearray){
						textValueDown = obj.valuearray[textValueDown];
					}
					obj.otext.setValue(textValueDown);
					
					if(obj.onmouseup) obj.onmouseup(textValueDown);
				});
			}
			obj.object.appendChild(obj.obuttondown.output());
			
			
			if(!obj.addbuttons){
				obj.obuttonup.onMouseUp(function(){
					getNumberUp = obj.otext.getValue();
					
					if(obj.valuearray) getNumberUp = new Number(NW3.core.array.arraySearch(getNumberUp, obj.valuearray));
					else getNumberUp = new Number(getNumberUp);
					
					if(obj.valuemax){
						if(obj.valuemax == getNumberUp) textValueUp = getNumberUp;
						else textValueUp = getNumberUp + 1;
					}
					else textValueUp = getNumberUp + 1;
					
					if(obj.valuearray){
						textValueUp = obj.valuearray[textValueUp];
					}
					obj.otext.setValue(textValueUp);
					
					if(obj.onmouseup) obj.onmouseup(textValueUp);
				});
			}
			obj.object.appendChild(obj.obuttonup.output());
			
			return obj.object;
		};
		
		obj.print = function(){
			NW3.core.object.print(obj.output());
		};
		
		obj.replace = function(targetElement){
			NW3.core.object.replace(targetElement, obj.output());
		};
		
		obj.insertAfter = function(targetElement){
			NW3.core.object.insertAfter(obj.output(), targetElement);
		};
		
		obj.insertBefore = function(targetElement){
			NW3.core.object.insertBefore(obj.output(), targetElement);
		};
		
		obj.appendChild = function(targetElement){
			NW3.core.object.appendChild(obj.output(), targetElement);
		};
		
		// set params
		if(params){
			obj.setWidth(params.width);
			obj.setValue(params.value);
			obj.setStatus(params.status);
			if(params.range) obj.setRange(params.range.begin, params.range.end);
			if(params.array) obj.setValueArray(params.value, params.array);
		}
		
		return obj;
	},
	
	Button : function(){
		var oButton = new NW3.form.Button();
		
		return oButton;
	}
};


NW3.form.Password  = function(params){
	params.inputType = "password";
	
	var oInput = NW3.form.Text(params);
	
	if(params.autogenerate){
		oInput.setValue( NW3.utils.Password.generateRandom(params.autogenerate.length, params.autogenerate.format) );
	}
	
	return oInput;
};